<?php
/* 
 * class.sellertlist.php
 * 我的城市首页-更多商家
 * @author samuel
 * @date 2009-06-02
 */
include_once 'class.mycityBase.php';
class mycity_sellerlist extends mycityBase {

    function  __construct($core) {
        parent::__construct();

        //参数处理
	    $this->page = $this->params['page'] ? (int)$this->params['page'] : 1;
	    $this->user_id = $this->params['uid'] ? (int)$this->params['uid'] : 0;
	    $this->stype = $this->params['stype'] ? strtolower(trim($this->params['stype'])) : 'all';
        $this->type = $this->params['type'] ? strtolower(trim($this->params['type'])) : '';
	    if(!$this->user_id){
		    $this->error = "用户ID不合法！";
		    $this->jumpError();
		    exit;
	    }
        $this->run();
    }

    function run(){
    	//WAP页面
	    //header("Content-type: text/vnd.wap.wml");
	    //TITLE
	    $page_title = "我的城市-首页";
	    $content = "";
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?stype=".$this->stype."&amp;uid=".$this->user_id."' alt='返回上级'>返回上级</a><br/>";
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?act=sellerlist&amp;stype=all&amp;uid=".$this->user_id."' alt='商家'>商家</a>|<a href='".$_SERVER['PHP_SELF']."?act=sellerlist&amp;stype=hot&amp;uid=".$this->user_id."' alt='最热'>最热</a>|<a href='".$_SERVER['PHP_SELF']."?act=sellerlist&amp;stype=latest&amp;uid=".$this->user_id."' alt='最新'>最新</a><br/>";
	    
	    //商家信息（10条，按时间排序）
	    $sellerBase = $this->core->load('seller::sellerBase');
	    $pagesize = 10;
	    $displaypage = 5;
	    $page = $this->page;
	    $current_url = $_SERVER['PHP_SELF']."?act=sellerlist&amp;uid=".$this->user_id."&amp;stype=".$this->stype;
	    if($this->stype == 'all' || $this->stype == 'latest'){
	        $arr_orderby = array("SellerID"=>"desc");
	    }elseif($this->stype == 'hot'){
	        $arr_orderby = array("SellerHits"=>"desc");
	    }

        $arr_filter = array();
        if($this->type == 'topclass'){
            $cid = $this->params['cid'];
            $current_url = $_SERVER['PHP_SELF']."?act=sellerlist&amp;uid=".$this->user_id."&amp;stype=".$this->stype."&amp;type=".$this->type."&amp;cid=".$cid;
            //获取子类
            $arr_sub_filter[] = array('attr'=>'SellerClassOwner','value'=>$cid);
            $all_subcate = $this->core->load('seller::sellerBase')->getSellerCateList($arr_sub_filter,'','');
            if($all_subcate['list']){
                foreach($all_subcate['list'] as $cate){
                    $arr_subcateid[] = $cate['SellerClassID'];
                }
            }
            $str_subcateids = @implode(',', $arr_subcateid);
            $arr_filter[] = array('attr'=>'SellerClassID', 'value'=>$str_subcateids, 'match'=>'in');
            $append = " AND `SellerClassID` IN (".$str_subcateids.") ";
        }elseif($this->type == 'area'){
            $aid = $this->params['aid'];
            $current_url = $_SERVER['PHP_SELF']."?act=sellerlist&amp;uid=".$this->user_id."&amp;stype=".$this->stype."&amp;type=".$this->type."&amp;aid=".$aid;
            $append = " AND `SellerAreaID`='".$aid."'";
            $arr_filter[] = array('attr'=>'SellerAreaID', 'value'=>$aid);
        }elseif($this->type == 'cbd'){
            $cid = $this->params['cid'];
            $current_url = $_SERVER['PHP_SELF']."?act=sellerlist&amp;uid=".$this->user_id."&amp;stype=".$this->stype."&amp;type=".$this->type."&amp;cid=".$cid;
            $append = " AND `SellerCBDID`='".$cid."'";
             $arr_filter[] = array('attr'=>'SellerCBDID', 'value'=>$cid);
        }elseif($this->type == 'cyclass'){
            $cid = $this->params['cid'];
            $current_url = $_SERVER['PHP_SELF']."?act=sellerlist&amp;uid=".$this->user_id."&amp;stype=".$this->stype."&amp;type=".$this->type."&amp;cid=".$cid;
            $append = " AND `SellerClassID` IN (".$cid.") ";
            $arr_filter[] = array('attr'=>'SellerClassID', 'value'=>$cid, 'match'=>'in');
        }

        $sql = "SELECT count(*) FROM `fun_seller` WHERE 1 AND `Del`='0'".$append;
        //echo $sql;
        $counts = $this->core->db->get_var($sql);
        $totalPages = ceil($counts/$pagesize);
        $pager = $this->core->utility->wap_pager($totalPages, $page, $displaypage, $current_url);
        $arr_filter[] = array('attr'=>'Del', 'value'=>'0');
        
        $arr_limit = array('page'=>$page, 'pagesize'=>$pagesize, 'url'=>'');
        $arr_info = $sellerBase->getInfoList(array('table'=>'fun_seller', 'primary'=>'SellerID'), "", $arr_filter, $arr_orderby, $arr_limit);
	        
	    $content .= $pager."<br/>";
	    if(is_array($arr_info['list'])){
	        foreach($arr_info['list'] as $info){
		    $content .= "<img src='' alt='' /><a href='./mycity.php?act=sellerinfo&amp;uid=".$this->user_id."&amp;sid=".$info['SellerID']."' alt=''>".$info['SellerNameCN']."</a><br/>";
	        }
	    }
	    $content .= $pager."<br/>";
	
//	    //商家顶级分类
//	    $arr_filter = array();
//	    $arr_filter[] = array('attr'=>'SellerClassOwner', 'value'=>'0');
//	    $arr_limit = array('page'=>1, 'pagesize'=>3, 'url'=>'');
//	    $arr_info = $sellerBase->getInfoList(array('table'=>'fun_seller_class', 'primary'=>'SellerClassID'), "", $arr_filter, array("SellerClassID"=>"desc"), $arr_limit);
//	    if(is_array($arr_info['list'])){
//	        $arr_tmp = array();
//	        foreach($arr_info['list'] as $info){
//		    $arr_tmp[] = "<a href='./cate.php?id=".$info['SellerClassID']."' alt=''>".$info['SellerClassName']."</a>";
//	        }
//	        $str_tmp = @implode('|', $arr_tmp);
//	        $content .= $str_tmp."<a href='' alt='更多'>>></a><br/>";
//	    }
//	    //商家地区
//	    $arr_limit = array('page'=>1, 'pagesize'=>3, 'url'=>'');
//	    $arr_info = $sellerBase->getInfoList(array('table'=>'fun_seller_area', 'primary'=>'SellerAreaID'), "", "", array("SellerAreaID"=>"desc"), $arr_limit);
//	    if(is_array($arr_info['list'])){
//	        $arr_tmp = array();
//	        foreach($arr_info['list'] as $info){
//		    $arr_tmp[] = "<a href='./cate.php?id=".$info['SellerAreaID']."' alt=''>".$info['SellerAreaNameCN']."</a>";
//	        }
//	        $str_tmp = @implode('|', $arr_tmp);
//	        $content .= $str_tmp."<a href='' alt='更多'>>></a><br/>";
//	    }
//	    //商家商圈
//	    $arr_limit = array('page'=>1, 'pagesize'=>3, 'url'=>'');
//	    $arr_info = $sellerBase->getInfoList(array('table'=>'fun_seller_cbd', 'primary'=>'SellerCBDID'), "", "", array("SellerCBDID"=>"desc"), $arr_limit);
//	    if(is_array($arr_info['list'])){
//	        $arr_tmp = array();
//	        foreach($arr_info['list'] as $info){
//		    $arr_tmp[] = "<a href='./cate.php?id=".$info['SellerCBDID']."' alt=''>".$info['SellerCBDNameCN']."</a>";
//	        }
//	        $str_tmp = @implode('|', $arr_tmp);
//	        $content .= $str_tmp."<a href='' alt='更多'>>></a><br/>";
//	    }
//	    //商家分类
//	    $arr_filter = array();
//	    $arr_filter[] = array('attr'=>'SellerClassOwner', 'value'=>'1');
//	    $arr_limit = array('page'=>1, 'pagesize'=>3, 'url'=>'');
//	    $arr_info = $sellerBase->getInfoList(array('table'=>'fun_seller_class', 'primary'=>'SellerClassID'), "", $arr_filter, array("SellerClassID"=>"desc"), $arr_limit);
//	    if(is_array($arr_info['list'])){
//	        $arr_tmp = array();
//	        foreach($arr_info['list'] as $info){
//		    $arr_tmp[] = "<a href='./cate.php?id=".$info['SellerClassID']."' alt=''>".$info['SellerClassName']."</a>";
//	        }
//	        $str_tmp = @implode('|', $arr_tmp);
//	        $content .= $str_tmp."<a href='' alt='更多'>>></a><br/>";
//	    }
        $userCustomeInfo = $this->core->load('myhome::myhomeBase')->getUserCustomeInfo($this->user_id);

	    //商家大类
	    if($userCustomeInfo['CustomtypeIs']){
	        $Customtype = $userCustomeInfo['Customtype'];
	        if($Customtype){
	            $arr_cids = explode(',', $Customtype);
	            $i = 1;
	            foreach($arr_cids as $cid){
	                if($i > 3) break;
	                $cate = $this->core->load('seller::sellerBase')->getSellerCateInfo($cid);
	                $content .= "<a href='".$_SERVER['PHP_SELF']."?act=sellerlist&stype=".$this->stype."&amp;uid=".$this->user_id."&amp;type=topclass&amp;cid=".$cate['SellerClassID']."'>".$cate['SellerClassName']."</a>|";
	                $i++;
	            }
	        }
	    }
        $content .= "<br/>";
	    //地区
	    if($userCustomeInfo['CustomqyIs']){
	        $Customqy = $userCustomeInfo['Customqy'];
	        if($Customqy){
	            $arr_ids = explode(',', $Customqy);
	            $i = 1;
	            foreach($arr_ids as $id){
	                if($i > 3) break;
	                $info = $this->core->load('seller::sellerBase')->getSellerAreaInfo($id);
	                $content .= "<a href='".$_SERVER['PHP_SELF']."?act=sellerlist&stype=".$this->stype."&amp;uid=".$this->user_id."&amp;type=area&amp;aid=".$info['SellerAreaID']."'>".$info['SellerAreaNameCN']."</a>|";
	                $i++;
	            }
	        }
	    }
	    $content .= "<br/>";
	    //商圈
	    if($userCustomeInfo['CustomsqIs']){
	        $Customsq = $userCustomeInfo['Customsq'];
	        if($Customsq){
	            $arr_ids = explode(',', $Customsq);
	            $i = 1;
	            foreach($arr_ids as $id){
	                if($i > 3) break;
	                $info = $this->core->load('seller::sellerBase')->getSellerCBDInfo($id);
	                $content .= "<a href='".$_SERVER['PHP_SELF']."?act=sellerlist&stype=".$this->stype."&amp;uid=".$this->user_id."&amp;type=cbd&amp;cid=".$info['SellerCBDID']."'>".$info['SellerCBDNameCN']."</a>|";
	                $i++;
	            }
	        }
	    }
	    $content .= "<br/>";
	    //餐饮类
	    if($userCustomeInfo['CustomCytypeIs']){
	        $CustomCytype = $userCustomeInfo['CustomCytype'];
	        if($CustomCytype){
	            $arr_ids = explode(',', $CustomCytype);
	            $i = 1;
	            foreach($arr_ids as $id){
	                if($i > 3) break;
	                $info = $this->core->load('seller::sellerBase')->getSellerCateInfo($id);
	                $content .= "<a href='".$_SERVER['PHP_SELF']."?act=sellerlist&stype=".$this->stype."&amp;uid=".$this->user_id."&amp;type=cyclass&amp;cid=".$cate['SellerClassID']."'>".$info['SellerClassName']."</a>|";
	                $i++;
	            }
	        }
	    }
	    $content .= "<br/>";
        
	    //搜索
	    $content .= "<input type='text' name='searchkeyword' value='' maxlength='20' size='15' />";
	    $content .= "<anchor title=\"搜索\">搜<go href=\"./search.php\" method=\"post\">
		        <postfield name=\"type\" value=\"city\" />
		        <postfield name=\"searchkeyword\" value=\"$(searchkeyword)\" />
		        </go></anchor><br/><br/><br/>";
	
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?stype=".$this->stype."&amp;uid=".$this->user_id."' alt='返回上级'>返回上级</a><br/>";
	    $content .= "<a href='' alt='建议帮助'>建议帮助</a>";



	    $this->core->tpl->assign('content', $content);
	    $this->core->tpl->assign('page_title', $page_title);
	    $this->core->tpl->display('comm.wml');
    
    }
}


?>
